package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyIrrigationCrop;
import com.ruoyi.ncpsy.service.INcpsyIrrigationCropService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 浇灌与作物关联Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/ncpsy/irrgatcrop")
public class NcpsyIrrigationCropController extends BaseController
{
    @Autowired
    private INcpsyIrrigationCropService ncpsyIrrigationCropService;

    /**
     * 查询浇灌与作物关联列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:irrgatcrop:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsyIrrigationCrop ncpsyIrrigationCrop)
    {
        startPage();
        List<NcpsyIrrigationCrop> list = ncpsyIrrigationCropService.selectNcpsyIrrigationCropList(ncpsyIrrigationCrop);
        return getDataTable(list);
    }

    /**
     * 导出浇灌与作物关联列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:irrgatcrop:export')")
    @Log(title = "浇灌与作物关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyIrrigationCrop ncpsyIrrigationCrop)
    {
        List<NcpsyIrrigationCrop> list = ncpsyIrrigationCropService.selectNcpsyIrrigationCropList(ncpsyIrrigationCrop);
        ExcelUtil<NcpsyIrrigationCrop> util = new ExcelUtil<NcpsyIrrigationCrop>(NcpsyIrrigationCrop.class);
        util.exportExcel(response, list, "浇灌与作物关联数据");
    }

    /**
     * 获取浇灌与作物关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:irrgatcrop:query')")
    @GetMapping(value = "/{waterCropId}")
    public AjaxResult getInfo(@PathVariable("waterCropId") Long waterCropId)
    {
        return success(ncpsyIrrigationCropService.selectNcpsyIrrigationCropByWaterCropId(waterCropId));
    }

    /**
     * 新增浇灌与作物关联
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:irrgatcrop:add')")
    @Log(title = "浇灌与作物关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyIrrigationCrop ncpsyIrrigationCrop) throws Exception {
        return toAjax(ncpsyIrrigationCropService.insertNcpsyIrrigationCrop(ncpsyIrrigationCrop));
    }

    /**
     * 修改浇灌与作物关联
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:irrgatcrop:edit')")
    @Log(title = "浇灌与作物关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyIrrigationCrop ncpsyIrrigationCrop)
    {
        return toAjax(ncpsyIrrigationCropService.updateNcpsyIrrigationCrop(ncpsyIrrigationCrop));
    }

    /**
     * 删除浇灌与作物关联
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:irrgatcrop:remove')")
    @Log(title = "浇灌与作物关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{waterCropIds}")
    public AjaxResult remove(@PathVariable Long[] waterCropIds)
    {
        return toAjax(ncpsyIrrigationCropService.deleteNcpsyIrrigationCropByWaterCropIds(waterCropIds));
    }
}
